﻿using System.IO;
using System.Windows.Forms;
using System.Xml;

namespace ProjectCom
{
    /// <summary>
    /// ParseXml 的摘要说明
    /// </summary>
    ///
    public class ParseXmlAppconfig
    {
        public static string strConfigFile;

        //*********************************************************
        //初始化配置文件
        //*********************************************************
        public static void InitFormConfigFile()
        {
            if (string.IsNullOrEmpty(ParseXmlAppconfig.strConfigFile))
            {
                string strPath = Application.StartupPath;
                strPath = strPath.Substring(0, strPath.LastIndexOf("\\"));
                strPath = strPath.Substring(0, strPath.LastIndexOf("\\"));
                strPath = strPath + "\\App.config";

                if (!File.Exists(strPath))
                {
                    PublicFunction.InitFormConfigFile();
                    return;
                }

                ParseXmlAppconfig.strConfigFile = strPath;
            }

            XmlDocument doc = new XmlDocument();
            doc.Load(ParseXmlAppconfig.strConfigFile);
            XmlNodeList nodeList = doc.SelectSingleNode("configuration").ChildNodes;
            foreach (XmlNode xn in nodeList)
            {
                if (xn.Name == "appSettings")
                {
                    XmlNodeList xmlNodeList = xn.ChildNodes;
                    foreach (XmlNode xmlNode in xmlNodeList)
                    {
                        switch (xmlNode.Attributes[0].Value)	//表达式的值只能是整型或字符串,字符
                        {
                            case "DBConnStr":
                                SystemInfo.Connstr = xmlNode.Attributes[1].Value;
                                break;
                            case "OLEDBConnStr":
                                SystemInfo.OLEConnstr = xmlNode.Attributes[1].Value;

                                break;
                            case "MaterialConnStr":
                                SystemInfo.MaterialConnStr = xmlNode.Attributes[1].Value;
                                SystemInfo.Conzhuwei = xmlNode.Attributes[1].Value;
                                break;
                            case "MaterialSelectSqlStr":
                                SystemInfo.MaterialSelectSqlStr = xmlNode.Attributes[1].Value;
                                break;
                            case "MaterialSupplier":
                                SystemInfo.MaterialSupplier = xmlNode.Attributes[1].Value;

                                break;
                            case "UnDeleteList":
                                SystemInfo.UnDeleteList = xmlNode.Attributes[1].Value;
                                break;
                            case "TopOrgStructID":
                                try
                                {
                                    SystemInfo.g_iTopOrgStructID = int.Parse(xmlNode.Attributes[1].Value);
                                }
                                catch
                                {
                                    SystemInfo.g_iTopOrgStructID = 1;
                                }
                                break;
                            case "EngineeringDepartment":
                                try
                                {
                                    SystemInfo.g_iEngineeringDepartment = int.Parse(xmlNode.Attributes[1].Value);
                                }
                                catch
                                {
                                    SystemInfo.g_iEngineeringDepartment = 1;
                                }

                                break;
                            case "TemplateID":
                                try
                                {
                                    SystemInfo.g_iTemplateID = int.Parse(xmlNode.Attributes[1].Value);
                                }
                                catch
                                {
                                    SystemInfo.g_iTemplateID = 1;
                                }
                                break;
                            case "IsTaskHasDefaultDate":
                                SystemInfo.TaskDefaultDate = xmlNode.Attributes[1].Value;

                                break;
                            case "Init":

                                break;
                            default:

                                break;
                        }
                    }
                }
            }

            //Log.Console.SetReleaseOut();
        }
    }
}